package experiments;

import java.awt.BorderLayout;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import main.Core;
import main.gui.workspace.WorkspaceListPanel;
import session.Session;
import character.GameCharacter;
import configuration.Paths;
import data.EditorObject;
import data.ObjectDatabase;

public class WorkspaceListTest {

	public static void main(String[] args) {
		// Set look and feel to default system look and feel
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			e.printStackTrace();
		}

		// Create Inventory Strategy
		System.err.println("Start Core");
		Core.getInstance().startup();
		System.err.println("Load Project");
		System.err.println(Paths.projectDataPath);
		Session.getInstance().loadProject("Test Project");
		ObjectDatabase.getInstance().addEditorObject(
				GameCharacter.class.getCanonicalName());
		ObjectDatabase.getInstance().addEditorObject(
				GameCharacter.class.getCanonicalName());
		ObjectDatabase.getInstance().addEditorObject(
				GameCharacter.class.getCanonicalName());
		String guid = "";
		for (EditorObject e : ObjectDatabase.getInstance()
				.getAllEditorObjectsOfClass(
						GameCharacter.class.getCanonicalName()).values()) {
			guid = e.getGUID();
		}

		// Display Frame
		final JFrame testFrame = new JFrame("Workspace Test");
		testFrame.setSize(600, 768);
		testFrame.setResizable(false);
		testFrame.setLayout(new BorderLayout());
		JScrollPane scroll = new JScrollPane(new WorkspaceListPanel(
				GameCharacter.class.getCanonicalName()));
		scroll
				.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		scroll
				.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
		testFrame.add(scroll, BorderLayout.CENTER);
		testFrame.setVisible(true);
		testFrame.addWindowListener(new WindowListener() {

			@Override
			public void windowActivated(WindowEvent arg0) {
				// TODO Auto-generated method stub

			}

			@Override
			public void windowClosed(WindowEvent arg0) {
				// TODO Auto-generated method stub

			}

			@Override
			public void windowClosing(WindowEvent arg0) {
				System.err.println("Close Project");
				Session.getInstance().closeProject();
				System.err.println("Shutdown Core");
				Core.getInstance().shutdown();
				testFrame.dispose();
			}

			@Override
			public void windowDeactivated(WindowEvent arg0) {
				// TODO Auto-generated method stub

			}

			@Override
			public void windowDeiconified(WindowEvent arg0) {
				// TODO Auto-generated method stub

			}

			@Override
			public void windowIconified(WindowEvent arg0) {
				// TODO Auto-generated method stub

			}

			@Override
			public void windowOpened(WindowEvent arg0) {
				// TODO Auto-generated method stub

			}

		});
	}
}
